import ch.aplu.nxt.Motor;
import lejos.nxt.Button;
import lejos.nxt.MotorPort;
import lejos.nxt.SensorConstants;
import lejos.nxt.SensorPort;


public class TestPoti {
	public TestPoti() throws Exception {
		SensorPort.S1.setTypeAndMode(SensorPort.SP_ANA, SensorConstants.MODE_RAW);
		if(SensorPort.S1.readRawValue() < 625)
			MotorPort.A.controlMotor(100, MotorPort.BACKWARD);
		else
			MotorPort.A.controlMotor(100, MotorPort.FORWARD);
		
		while (Button.ESCAPE.isUp()) {
			SensorPort.S1.setTypeAndMode(SensorPort.SP_ANA, SensorConstants.MODE_RAW);
			if (SensorPort.S1.readRawValue() > 950) {
				MotorPort.A.controlMotor(100, MotorPort.STOP);
				System.out.println(SensorPort.S1.readRawValue());
				Thread.sleep(500);
				MotorPort.A.controlMotor(100, MotorPort.BACKWARD);
				Thread.sleep(1000);
			}
			else if (SensorPort.S1.readRawValue() < 300) {
				MotorPort.A.controlMotor(100, MotorPort.STOP);
				System.out.println(SensorPort.S1.readRawValue());
				Thread.sleep(500);
				MotorPort.A.controlMotor(100, MotorPort.FORWARD);
				Thread.sleep(1000);
			}
			SensorPort.S1.setSensorPinMode(0, 1);
			SensorPort.S1.setSensorPinMode(1, 1);
			if(SensorPort.S1.getSensorPin(0)== 0 || SensorPort.S1.getSensorPin(1) == 0)
				System.out.println("Achtung!");
		}
	}
	
	public static void main(String[] args) throws Exception {
		new TestPoti();
	}

}
